home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagg_m.zip / MISC.SWG / 0054_POKER Again and Again.pas < prev    next >
Pascal/Delphi Source File  |  1993-11-02  |  2KB  |  80 lines

  1. {
  2. LEE BARKER
  3.  
  4. │ I'm trying to Write a small Poker game For a grade in my
  5. │ High School Pascal Class.
  6.  
  7. While the Array of Strings will work, it is a lot of overhead
  8. for what you want to do. It is also difficult to do the scoring.
  9. The following is a small piece of code I posted a year or two
  10. ago when someone asked a similar question. Offered as a study
  11. guide For your homework.
  12. }
  13.  
  14. Const
  15.   Limit    = 5; { Minimum cards before reshuffle }
  16.   MaxDecks = 1; { Number of decks in use }
  17.   NbrCards = MaxDecks * 52;
  18.   Cardvalue : Array [0..12] of String[5] =
  19.                 ('Ace','Two','Three','Four','Five','Six','Seven',
  20.                  'Eight','Nine','Ten','Jack','Queen','King');
  21.   Suit : Array [0..3] of String[8] =
  22.            ('Hearts','Clubs','Diamonds','Spades');
  23.  
  24. Type
  25.   DeckOfCards = Array [0..Pred(NbrCards)] of Byte;
  26.  
  27. Var
  28.   Count,
  29.   NextCard : Integer;
  30.   Cards    : DeckOfCards;
  31.  
  32. Procedure shuffle;
  33. Var
  34.   i, j,
  35.   k, n : Integer;
  36. begin
  37.   randomize;
  38.   j := 0;  { New Decks }
  39.   For i := 0 to pred(NbrCards) do
  40.   begin
  41.     Cards[i] := lo(j);
  42.     inc(j);
  43.     if j > 51 then
  44.       j := 0;
  45.   end;
  46.   For j := 1 to 3 do { why not ? }
  47.     For i := 0 to pred(NbrCards) do
  48.     begin { swap }
  49.       n := random(NbrCards);
  50.       k := Cards[n];
  51.       Cards[n] := Cards[i];
  52.       Cards[i] := k;
  53.     end;
  54.   NextCard := NbrCards;
  55. end;
  56.  
  57. Function CardDealt : Byte;
  58. begin
  59.   Dec(NextCard);
  60.   CardDealt := Cards[NextCard];
  61. end;
  62.  
  63. Procedure ShowCard(b : Byte);
  64. Var
  65.   c, s : Integer;
  66. begin
  67.   c := b mod 13;
  68.   s := b div 13;
  69.   Writeln('The ', Cardvalue[c], ' of ', Suit[s]);
  70. end;
  71.  
  72. begin
  73.   Shuffle;
  74.   Writeln('< The deck is shuffled >');
  75.   { if NextCard <= Limit then shuffle }
  76.   For Count := 1 to 5 do
  77.     ShowCard(CardDealt);
  78.   Readln;
  79. end.
  80.